package com.zhuchang.self_rpc.test.config;

import com.zhuchang.self_rpc.test.server.RpcServer;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.PriorityQueue;

/**
 * @Author RenPu
 * @Date 2021/8/19 10:26
 * @Version 1.0
 * @Description: 服务端启动配置类
 **/

@Slf4j
public class RpcServerConfig {

    private final String host = "127.0.0.1";

    protected int port;

    private List<ProviderConfig> providerConfigList;

    private RpcServer server = null;


    public RpcServerConfig(List<ProviderConfig> providerConfigList) {
        this.providerConfigList = providerConfigList;
    }


    /**
     * 启动方法
     */
    public void exporter() {
        if (server == null) {
            try {
                server = new RpcServer(host + ":" + port);
            } catch (InterruptedException e) {
                log.error("RpcServerConfig  exporter Exception " + e);
            }
        }

        for (ProviderConfig providerConfig : providerConfigList) {
            server.registerProcessor(providerConfig);
        }


    }


    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public List<ProviderConfig> getProviderConfigList() {
        return providerConfigList;
    }

    public void setProviderConfigList(List<ProviderConfig> providerConfigList) {
        this.providerConfigList = providerConfigList;
    }
}
